package com.songlanyun.modules.integralconfig.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.songlanyun.common.utils.BeanUtil;
import com.songlanyun.common.validator.ValidatorUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.Query;

import com.songlanyun.modules.integralconfig.dao.IntegralConfigDao;
import com.songlanyun.modules.integralconfig.entity.IntegralConfig;
import com.songlanyun.modules.integralconfig.service.IntegralConfigService;

import javax.validation.Validator;


@Service("integralConfigService")
public class IntegralConfigServiceImpl extends ServiceImpl<IntegralConfigDao, IntegralConfig> implements IntegralConfigService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<IntegralConfig> page = this.page(
                new Query<IntegralConfig>().getPage(params),
                new QueryWrapper<IntegralConfig>()
        );

        return new PageUtils(page);
    }

    @Override
    public void saveIntegralConfig(IntegralConfig integralConfig) {

        IntegralConfig config = this.get();
        if (config == null) {
            this.baseMapper.insert(integralConfig);
        } else {
            integralConfig.setId(config.getId());
            BeanUtil.copyPropertiesIgnoreNull(integralConfig,config);
            this.baseMapper.updateById(config);
        }
    }

    @Override
    public IntegralConfig get() {
        return this.baseMapper.selectOne(
                new LambdaQueryWrapper<IntegralConfig>().last("limit 1")
        );
    }


}